package com.bluesea.report.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.bluesea.report.entity.CustomerDetail;
import com.bluesea.report.service.customer.CustomerDetailService;


/**
 * 控制层调
 * @ClassName: CustomerController
 * @author 李爽
 * @date 2017年8月16日 下午6:50:58
 * @version V1.0
 */

@Controller
@RequestMapping("customerDetail")
public class CustomerDetailController {
	
    @SuppressWarnings("unused")
	@Autowired
    private HttpServletRequest req; 
    @SuppressWarnings("unused")
	@Autowired
    private HttpServletResponse res; 
    
    @Resource//将CustomerDetailService类注入
	private CustomerDetailService service; 
    
    /**
     * 查询全部
     * @Title: getAll
     * @return String    返回类型
     */
	@RequestMapping(value="/customers",method=RequestMethod.GET)
	@ResponseBody
	public String getAllCustomerDetail(){
		List<CustomerDetail> customers = service.getAllCustomerDetail(); //调service里的查询所有的方法
		return JSONArray.toJSONString(customers);
	}
	
//	/**
//	 * 条件查询
//	 * @Title: search
//	 * @param @param customer
//	 * @return String    返回类型
//	 */
//	@RequestMapping(value="/customers",method=RequestMethod.POST)
//	@ResponseBody
//	public String searchCustomerDetail(@RequestBody CustomerDetail custDetail){
//		List<CustomerDetail> customers = null;//调service里的条件查询的方法
//		try {
//			
//			//调用Service层业务处理
//			customers = service.searchCustomerDetail(custDetail);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return JSONArray.toJSONString(customers);
//	}
//	
//
//	
	/**
	 * 删除
	 * @Title: search
	 * @param @param customer
	 * @return String    返回类型
	 */
	@RequestMapping(value="/delete",method=RequestMethod.DELETE)
	@ResponseBody
	public String removeCustomerDetail(@RequestBody Integer[] ids){
		String success="";
		try {
    		//调用Service层业务处理
			service.deleteBatchCustomerDetail(ids);
    		success = "true";
		} catch (Exception e) {
			e.printStackTrace();
			success = "false";
		}
		return JSONArray.toJSONString(success);	
	}

	/**
	 * 增加
	 * @Title: search
	 * @param @param customer
	 * @return String    返回类型
	 */
	@SuppressWarnings("unused")
	@RequestMapping(value="/insert",method=RequestMethod.POST)
	@ResponseBody
	public String createCustomerDetail(@RequestBody CustomerDetail custDetail){
		String success = "true";
		Integer create=service.createCustomerDetail(custDetail);//调service里的增加方法
		List<CustomerDetail> customers = service.getAllCustomerDetail(); //调service里的查询所有的方法
		return JSONArray.toJSONString(customers);
		
	}

	/**
	 * 修改
	 * @Title: search
	 * @param @param customer
	 * @return String    返回类型
	 */
	@RequestMapping(value="/update",method=RequestMethod.PUT)
	@ResponseBody
	public String modifyCustomerDetail(@RequestBody CustomerDetail custDetail){
		String success="";
		try {
    		service.modifyCustomerDetail(custDetail);
    		success = "true";
		} catch (Exception e) {
			e.printStackTrace();
			success = "false";
		}
		return JSONArray.toJSONString(success);
	}
	
	/**
	 * 批量撤户
	 */
	@RequestMapping(value="/invalid",method=RequestMethod.PUT)
	@ResponseBody
	public String invalidCustomerDetail(@RequestBody Integer[] id) {
    	
    	String success = "";
    	try {
			//调用Service层业务处理
    		service.invalidCustomerDetail(id);
    		success = "true";
		} catch (Exception e) {
			e.printStackTrace();
			success = "false";
		}
		return JSONArray.toJSONString(success);
    };
}
